package com.aboo.action.personnel;

import java.util.List;

import org.apache.log4j.Logger;

import com.aboo.action.BaseAction;
import com.aboo.parameter.personnel.LoginParameter;
import com.aboo.po.personnel.LoginPO;
import com.aboo.service.personnel.ILoginService;
import com.aboo.util.StringUtils;

public class LoginAction extends BaseAction {

	private static final long serialVersionUID = -2447429201135883868L;
	private static final Logger logger = Logger.getLogger(LoginAction.class);
	
	private ILoginService loginService;
	
	private String name;
	private String password;
	
	public String execute() throws Exception {
		if (!StringUtils.isBlank(name)) {
			this.name = this.name.trim();
			this.password = this.password.trim();
			
			LoginParameter loginPara = new LoginParameter();
			loginPara.setName(this.name);
			loginPara.setPassword(this.password);
			
			List<LoginPO> result = loginService.findByCondition(loginPara);
			if (result != null && result.size() > 0) {
				this.setContent("Hello," + this.name + "!You are Login In success!");
				return SUCCESS;
			} else {
				this.setContent("Sorry!Name or Password is Error!");
				return ERROR;
			}
		}
		
		this.setContent("You name is empty!");
		return ERROR;
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public ILoginService getLoginService() {
		return loginService;
	}
	public void setLoginService(ILoginService loginService) {
		this.loginService = loginService;
	}

}
